<?php
class Car_model extends CI_Model
{
	function __construct()
	{
		parent::__construct();
	}
	
	function GetAllCars()
	{
		$sqlCommand=('select distinct(id) from bil');
		$result=$this->db->query($sqlCommand);
		
		if ($result->num_rows()>=1)
		{
			return $result->result_object();
		}
		else
		{
			return FALSE;
		}
	}
	
	function GetAllFreeCars($id=NULL,$priceClass,$startDate=NULL,$endDate=NULL)
	{
		$sqlCommand=("call studentbilar.spCheckIfCarFree(?,?,?,?)");
		$result=$this->db->query($sqlCommand,array($id,$priceClass,$startDate,$endDate));
		$result->result_object();
		
		if($result->num_rows()>=1)
			{
				return $result->row_object(0);
			}
			else
			{
				return FALSE;
			}

	}
	function checkIfCarFree($carID,$date,$Otime)
	{
		$sqlCommand=("call studentbilar.spcheckIfCarFreePerHour(?,?,?)");
		$result=$this->db->query($sqlCommand,array($carID,$date.' '.$Otime->startDate,$date.' '.$Otime->endDate));
		
		if($result->num_rows()>=1)
		{
			return TRUE;
		}
		else
		{
			return FALSE;
		}
	}
	function GetCarInfo($carId)
	{
		$sqlCommand=("select* from bil where id=?");
		$result=$this->db->query($sqlCommand,array($carId));
		
		if($result->num_rows()>=1)
		{
			return $result->result_object();
		}
		else
		{
			return FALSE;
		}
	}	
}	
?>